package com.lcxw.hxzbadmin.controller.roomcontroller;

import com.lcxw.hxzbadmin.entity.requestbean.AddRoomRecommendReq;
import com.lcxw.hxzbadmin.entity.requestbean.DeleteRoomRecommend;
import com.lcxw.hxzbadmin.entity.requestbean.GetRoomRecommendListReq;
import com.lcxw.hxzbadmin.entity.requestbean.ModRoomRecommend;
import com.lcxw.hxzbapi.entity.response.Response;
import com.lcxw.hxzbapi.service.RoomRecommendService;
import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/admin/roomRecommend")
@Slf4j
public class RoomRecommendController {

    @Resource
    RoomRecommendService roomRecommendService;

    //添加一个房间推荐
    @PostMapping("/add")
    public Response addRoomRecommend(@Valid @RequestBody AddRoomRecommendReq addRoomRecommendReq) {
        long userId = addRoomRecommendReq.getUserId();
        int position = addRoomRecommendReq.getPosition();
        return roomRecommendService.addRoomRecommend(userId, position);
    }

    //获取推荐位列表
    @PostMapping("/getList")
    public Response getRoomRecommendList(
        @Valid @RequestBody GetRoomRecommendListReq getRoomRecommendListReq) {
        int pageNum = getRoomRecommendListReq.getPageNum();
        int pageSize = getRoomRecommendListReq.getPageSize();
        Integer position = getRoomRecommendListReq.getPosition();
        return roomRecommendService.getList(position, pageNum, pageSize);

    }

    //删除一个推荐位
    @PostMapping("/delete")
    public Response deleteRoomRecommend(@RequestBody DeleteRoomRecommend deleteRoomRecommend) {
        int id = deleteRoomRecommend.getId();
        roomRecommendService.removeById(id);
        return Response.ok();
    }

    //修改一个房间推荐位
    @PostMapping("/mod")
    public Response modRoomRecommend(@Valid @RequestBody ModRoomRecommend modRoomRecommend) {
        int id = modRoomRecommend.getId();
        int position = modRoomRecommend.getPosition();
        return roomRecommendService.modRoomRecommend(id, position);
    }

}
